<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>
<body>

<script src="../lib/three.js"></script>
<script src="../lib/OrbitControls.js"></script>
<script>
    const scene = new THREE.Scene()

    const geometry = new THREE.BufferGeometry()
    const vertices = new Float32Array([
        0, 0, 0, // 顶点1坐标
        50, 0, 0, // 顶点2坐标
        0, 100, 0, // 顶点3坐标
        0, 0, 0, // 顶点4坐标
        0, 0, 100, // 顶点5坐标
        50, 0, 0, // 顶点6坐标
    ])
    geometry.attributes.position = new THREE.BufferAttribute(vertices, 3)

    const normals = new Float32Array([
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
        0, 1, 0,
        0, 1, 0,
        0, 1, 0,
    ])
    geometry.attributes.normal = new THREE.BufferAttribute(normals, 3)

    const material = new THREE.MeshBasicMaterial({
        color: 0x0000ff,
        side: THREE.DoubleSide, // 两面可见
    })
    const mesh = new THREE.Mesh(geometry, material)
    scene.add(mesh)

    const pointLight = new THREE.PointLight(0xffffff)
    pointLight.position.set(200, 200, -200)
    console.log(pointLight)
    scene.add(pointLight)

    const ambientLight = new THREE.AmbientLight(0xffffff)
    scene.add(ambientLight)

    const axesHelper = new THREE.AxesHelper(200)
    scene.add(axesHelper)

    const width = window.innerWidth
    const height = window.innerHeight
    const k = width / height
    const s = 100
    const camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000)
    camera.position.set(300, 300, 300)
    camera.lookAt(scene.position)

    const renderer = new THREE.WebGLRenderer()
    renderer.setSize(width, height)
    renderer.setClearColor(0xb9d3ff, 1)
    renderer.shadowMap.needsUpdate = true
    renderer.shadowMap.enabled = true
    document.body.appendChild(renderer.domElement)

    renderer.render(scene, camera);

    (function () {
        const geometry = new THREE.SphereGeometry(30, 10, 10)
        const material = new THREE.MeshPhongMaterial({
            color: 0x0000ff,
            specular: 0x4488ee,
            shininess: 12,
        })
        const mesh = new THREE.Mesh(geometry, material) // 网格模型对象Mesh
        mesh.position.set(0, 0, 0)
        scene.add(mesh)
    })()

    renderer.render(scene, camera)

    let T0 = new Date()

    function render() {
        const T1 = new Date()
        const t = T1 - T0
        T0 = T1
        requestAnimationFrame(render)
        renderer.render(scene, camera)
        // mesh.rotateY(0.001 * t)
    }

    render()

    new THREE.OrbitControls(camera, renderer.domElement)
</script>
</body>
</html>
